#include "StdThread.h"
#include <stdio.h>

RWMutex *rw;

int count = 0;
void* ReadThread(void *arg)
{
    RwReadLock(rw);
    printf("读:%d\n",count);
    RWReadUnlock(rw);
    return NULL;
}

void* WriteThread(void* arg)
{
    RWWritelock(rw);
    count++;
    printf("写:%d\n",count);
    RWWriteUnlock(rw);
    return NULL;
}
int main()
{   
    rw = RWMutexInit();

    Thread*read[3];
    Thread*write[2];

    for(int i = 0;i < 3;i++)
    {
        read[i] = ThreadInit(ReadThread,NULL);
    }

    for(int i = 0;i < 2;i++)
    {
        write[i] = ThreadInit(WriteThread,NULL);
    }
    
    for(int i = 0;i < 3;i++)
    {
         ThreadJoin(read[i]);
    }

    for(int i = 0;i < 2;i++)
    {
         ThreadJoin(write[i]);
    }

    ClearRwMutex(rw);
}